import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-03-12
 * Time: 8:28
 */
public class Test {
    public static int singleNumber(int[] nums) {
        int result = 0;
        for (int i = 0; i < 32; i++) {
            int sum = 0;
            for (int j = 0; j < nums.length; j++) {
                sum += ((nums[j] >> i) & 1);
            }
            if(sum % 3 != 0){
                result |= (1 << i);
            }
        }
        return result;
    }

    public static void main(String[] args) {      //题目：找出只出现过一次的元素
        int[] arr = {1,2,3,4,5,1,2,3,4,6,5};
        int ret = singleNumber(arr);
        System.out.println(ret);
    }

/*    public static int[] searchSum(int[] arr, int target){
        //int[][] arr2 = new int[arr.length][];
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] + arr[j] == target){
                    return new int[]{i, j};
                }
            }
        }
        return new int[0];
    }

    public static void main(String[] args) {   //题目：找出和为terget的元素下标
        int[] arr = {1,2,3,4,5,6,7};
        int target = 9;
        int[] arr2 = searchSum(arr, target);
        System.out.println(Arrays.toString(arr2));
    }*/

/*
    public static void moveArr(int[] arr){
        int left = 0;
        int right = arr.length - 1;
        while(left <= right ){
            if(iseven(arr[left]) && !iseven(arr[right])){
                int temp = arr[left];
                arr[left] = arr[right];
                arr[right] = temp;
                left++;
                right--;
            }
            else if(iseven(arr[left]) && iseven(arr[right])){
                right--;
            }
            else if(!iseven(arr[left]) && iseven(arr[right])){
                left++;
                right--;
            }
            else if(!iseven(arr[left]) && !iseven(arr[right])){
                left++;
            }
        }
        System.out.println(Arrays.toString(arr));
        //for (int i = 0; i < arr.length; i++) {
        //    System.out.println(arr[i]);
        //}
    }
    public static boolean iseven(int num){   //判断是否为偶数
        return (num & 1) == 0;
    }

    public static void main(String[] args) {    //题目：奇数位于偶数之前
        int[] arr = {1,2,3,4,5,6,8,8,8,8};
        moveArr(arr);

    }
*/

/*    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        int[][] arr1 = {{4,5,6},{1,2,3},{7,8,9}};
        int[] copy = new int[arr.length];
        int[] ret = Arrays.copyOfRange(arr, 1, 3);  //[1, 3)左闭右开，用Arrays.copyOfRange(数组名，from， to)；
        System.out.println(Arrays.toString(ret));
        System.out.println("===========");
        for (int[] tmp : arr1) {
            for (int x : tmp) {
                System.out.print(x + " ");
            }
            System.out.println();
        }
        System.out.println("===========");
        String ret1 = Arrays.deepToString(arr1);     //二位数组利用Arrays.deepToSort（数组名）可以直接打印，不需要遍历
        System.out.println(ret1);
    }*/
/*
    public static void bubbleSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 1; j < arr.length-i; j++) {
                if (arr[j-1] > arr[j]) {
                    int tmp = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = tmp;
                }
            }
        } // end for
    }

    public static void main(String[] args) {    //冒泡排序
        int[] arr = {9, 5, 7, 2, 11, 13, 1};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }
*/


/*    public static int findVal(int[] arr, int num){
        int left = 0;
        int right = arr.length - 1;
        while(left <=right){
            int mid = (left + right)/2;
            if(arr[mid] > num){
                right -= mid;
            }else if(arr[mid] < num){
                left += mid;
            }else if(arr[mid] == num){
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {     //二分法查找
        int[] arr = {1,9,8,2,5};
        int n = 4;
        Arrays.sort(arr);                        //Arrays.sort java自带的排序代码、Arrays.copyOf数组拷贝
        System.out.println(Arrays.toString(arr));
        int ret = findVal(arr, n);
        if(ret == -1){
            System.out.println("没找到 " + n + " 这个数字");
        }else {
            System.out.println("此数字的下标是：" + ret);
        }
    }*/

/*    public static String myToString(int[] arr){
        if(arr == null){
            return "null";
        }
        String arr1 = "[";
        int count = arr.length - 1;

        for (int i = 0; i < arr.length; i++) {
            arr1 += arr[i];
            if(count-- != 0){
                arr1 += ",";
            }
        }
        arr1 += "]";
        return arr1;
    }
    public static void main(String[] args) {    //模拟实现Arrays.toString
        int[] arr = null;
        String ret = myToString(arr);
        System.out.println(ret);
    }*/

 /*   public static double avg(int[] arr, int n){
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += arr[i];
        }
        return sum/n;
    }

    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < 10; i++) {
            arr[i] = i + 1;
        }
        double ret = avg(arr, 10);
        System.out.println("所有元素的平均值为：" + ret);
    }*/

/*    public static void sum(int[] arr, int n){
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += arr[i];
        }
        System.out.println("所有元素之和为：" + sum);
    }

    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < 10; i++) {
            arr[i] = i + 1;
        }
        sum(arr, 10);
    }*/

/*    public static void transform(int[] arr, int n){
        for (int i = 0; i < n; i++) {
            arr[i] *= 2;
        }
        System.out.println("乘以2后的结果为：" + Arrays.toString(arr));
    }

    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < 10; i++) {
            arr[i] = i + 1;
        }
        System.out.println("原来数组为：" + Arrays.toString(arr));
        transform(arr, 10);
    }*/

 /*  public static void printArray(int[] arr){
       System.out.println(Arrays.toString(arr));
   }

    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < 10; i++) {
            arr[i] = i + 1;
        }
        printArray(arr);
    }*/

/*    public static void main(String[] args) {
        int[] arr = new int[100];
        for (int i = 0; i < 100; i++) {
            arr[i] = i + 1;
        }
        System.out.println(Arrays.toString(arr));
    }*/

/*
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        int[] arr2 = new int[]{1,2,3,4,5,6};
        int[] arr3 = new int[5];
        String[] arr4 = new String[10];  //存-->null 小写的
        boolean[] arr5 = new boolean[10]; //存-->false
        for (int x : arr) {
            System.out.print(x+" ");
        }
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        System.out.println("===============");
        System.out.println(Arrays.toString(arr));
        System.out.println(arr); //arr叫做引用变量，这个arr指向了一个对象，就是说引用会指向对象。
    }
*/

/*    public static int Fib2(int n){
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = -1;
        for (int i = 3; i <= n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static void main(String[] args) {    //第N项斐波那锲数列(利用循环)
        int ret = Fib2(5);
        System.out.println(ret);
    }*/

/*
    public static int Fib(int a){
        if(a == 1){
            return 0;
        }
        else if(a == 2){
            return 1;
        }
        return Fib(a-1)+Fib(a-2);
    }
    public static void main(String[] args) {    //第N项斐波那锲数列（利用递归）循环冗余，不推荐。
        int ret = Fib(5);
        System.out.println(ret);
    }*/
}

